﻿using UnityEngine;
using System.Collections;
using LitJson;
using com.bot.game.shuankou.msg;
using System.IO;

using System.Linq;
/// <summary>
/// 游戏的入口函数
/// </summary>
/// 
public class SQManager : GameManager
{


    public override void onStart()
    {
        #region
        // json 数据测试。改成Pb 。邱伟森定 发送命令位置
        string playerJson = @"
                            {
                            
                            ""userName"": ""caojianhua"",
                            ""richTitle"": ""富可敌国"",
                            ""achieveTitle"": ""Q圣"",
                            ""price"": 10000,
                            ""standings"": 100,
                            ""winRate"": 30,
                            ""vipLevel"": 5,
                            ""weekWinIntegral"": 200,
                            ""topRecond"": 10,
                            ""weekWinningStreak"": 3,
                            ""streakRecond"": 5
                            
                            }
                            ";


        GlobalDataManager.instance.playerData = JsonMapper.ToObject<PlayerInfo>(playerJson);
     
       // NetDataHandler.getInstance().LinkGame("ngrok.com", 46885);

        /*using (MemoryStream m = new MemoryStream())
        {
            // C2S data
            RegisterAccountC2S data = new RegisterAccountC2S();

            data.name = "caojianhua";

            data.password = "31";

            data.isPhone = true;


            NetDataHandler.getInstance().SendPacket(18001, data);*/
          //  byte[] s2c = NetDataHandler.send(18001, NetUtil.serializeProtoObject<RegisterAccountC2S>(data));
            
         //   if (s2c != null )
          //  {
          //      RegisterAccountS2C _regS2C = NetUtil.deserialzeProtoObject<RegisterAccountS2C>(s2c);            
          //  }

            // C2S data PB 序列化
            /*    ProtoBuf.Serializer.Serialize<RegisterAccountC2S>(m, data);

                byte[] pbData = m.ToArray();

                int pblength = pbData.Length;
                // 编号的四字节, PbData序列化长度信息的四字节
                byte[] commandHead = new byte[4];

                commandHead = System.BitConverter.GetBytes(18001);

                byte[] packageLength = new byte[4];

                packageLength = System.BitConverter.GetBytes(pblength);
                // 拼接发送的字节流信息           

                Stream c2s = new MemoryStream();

                c2s.Write(commandHead, 0, commandHead.Length);

                c2s.Write(packageLength, 0, packageLength.Length);

                c2s.Write(pbData, 0, pblength);

                // byte[] sendByte = commandHead.Concat(packageLength).Concat(pbData).ToArray();
                // c2s.Write(sendByte, 0, sendByte.Length);*/
        //}

        // RegisterAccountS2C _regS2C = 
        //     NetDataHandler.deserialzeProtoObject<RegisterAccountS2C>(
        //     NetDataHandler.transNetData(NetDataHandler.serializeProtoObject<RegisterAccountC2S>(reg))
        //     );
        #endregion
    }

}
